<?php

if( !defined('IN_SEC') ){
	exit('Access Denied.');
}

class Session{
	private static $_begin = 0;
	private static $_instance = null;

	public static $initiated;

	public static function init(){
		self::$_instance = new Session();
		self::$initiated = session_start();
		return self::$initiated ? self::add('__init_time__', microtime()) : self::$initiated;
	}

	public static function add($name, $value){
		if ( !self::get($name) ){
			return self::set($name, $value);
		}
		return false;
	}

	public static function set($name, $value){
		$_SESSION[$name] = $value;
		return $value;
	}

	public static function get($name, $once = 0){
		if( isset($_SESSION[$name]) ){
			$return = $_SESSION[$name];
			if ( $once ){
				self::del($name);
			}
			return $return;
		}
		return false;
	}

	public static function del($name){
		unset($_SESSION[$name]);
		return true;
	}

	public function __construct(){
		self::$_begin = microtime(true);
	}

	public function __destruct(){
		DB::Close();
		$output = ob_get_clean();
		$output = render_hook($output);
		die(output_hook($output));
	}

}

?>